<?php

include 'SMSSend.php';

class Recibo{
	private static $_instance;
	public static function getInstance() {if (!(self::$_instance instanceof self)) {self::$_instance = new self();}return self::$_instance;}
	// Do not allow an explicit call of the constructor: $v = new Singleton();
	final private function __construct() {}
	// Do not allow the clone operation: $x = clone $v;
	final private function __clone() {}

        public static function sms(){
                        
            $DocObjct = $_GET['OB'];
            $sql="SELECT FraID,
			FraOrigen0,
			origenes.OriDireccion,
			origenes.Oriciudad,
			origenes.OriProvincia,
			origenes.OriTelefono,
			FraOrigen1,
			origenes.OriNombre,
			FraReferenciaAg,
			FraFechaIngreso,
			FraFechaAlb,
			FraFecha,
			FraMTCN,
			FraCargoUSD,
			FraEnviadoUSD,
			FraEnviado,
			FraARecibir,
			FraCambio,
			FraTasa,
			FraTasaAgn,
			FraCargo,
			FraMonCobro,
			FraMonDPago,
			FraMonPagoISO,
			FraStatus,
			FraMensaje,
			FraNotas,
			FraConcepto,
			FraCliNumero,
			FraProm,
			FraTaxProm,
			FraModo,
			FraModoPago,
			FraAgenciaPago,
			FraCliNumero AS CliNumero,
			FraCliNombre AS CliNombre,
			FraCliDomicilio AS CliDomicilio,
			FraCliPisoPuerta AS CliPisoPuerta,
			FraCliPortal AS CliPortal,
			FraCliLocation AS CliLocation,
			FraCliNacionalidad AS CliNacionalidad,
			FraCliDNI AS CliDNI,
			FraCliCiudad AS CliCiudad,
			FraCliCP AS CliCP,
			FraCliTelefono AS CliTelefono,
			FraCliTelefono2 AS CliTelefono2,
			FraCliObs AS ClObs,
			FraBnfNombre AS BnfNombre,
			FraBnfNumero AS BnfNumero,
			IF(FraModo=1,BnfNumExt,FraConcepto) AS BnfNumExt,
			FraBnfDireccion AS BnfDireccion,
			FraBnfCedula AS BnfCedula,
			FraBnfCiudad AS BnfCiudad,
			FraBnfTelefono AS BnfTelefono,
			FraBnfPais AS BnfPais,
			FraBnfBarrio AS BnfBarrio,
			FraCtaBenef AS cb_Id,
			FraCuenta AS cb_Cuenta,
			FraBancoID AS BancoID,
			FraCuenta_mod AS cb_Cuenta_mod,
			FraCuenta_prx AS cb_Cuenta_prx,
			FraCuenta_sux AS cb_Cuenta_sux,
			FraSucursal AS cb_Sucursal,
			FraCiudadSucursal AS cb_CiudadSucursal,
			FraTipoCuenta AS cb_Tp,
			bp_Name AS cb_Banco,
			miso_ID,
			mp_ModoPago,
			IF(FraModo=1,OutCorresponsal.CorrNombre,IncCorresponsal.CorrNombre) AS CorrNombre,
			IF(FraModo=1,OutCorresponsal.CorrNumero,IncCorresponsal.CorrNumero) AS CorrNumero,
			IF(FraModo=1,OutCorresponsal.CorrDireccion,IncCorresponsal.CorrDireccion) AS CorrDireccion,
			IF(FraModo=1,OutCorresponsal.CorrAdicionalMailText,IncCorresponsal.CorrAdicionalMailText) AS CorrAdicionalMailText,
			IF(FraModo=1,OutCorresponsal.CorrReceipt,IncCorresponsal.CorrReceipt) AS CorrReceipt,
			cpd_Text,
			ori1.OriTipo AS Ori1Tipo,
			ori1.OriNombre AS Ori1Nombre,
			tdc_Tipo AS BnfDocType,
			hf_actypes.TYPE_NAME AS cb_TipoCuenta,
			hd_bancos.bp_Name AS cb_Banco,
			Prov_Provincia AS BnfProvincia,
			cp_cacn.CiuCiudad AS cb_CiudadSucursal,
			cp_cbnf.CiuCiudad AS BnfCiudad,
			smb_Name AS UserName,
			FraReferenciaMB as referencia
			FROM officeschema.facturas
				INNER JOIN officeschema.facturasextjoins ON FraExtID = FraID
				LEFT JOIN officeschema.facturas_income ON FraIncID = FraID
				LEFT JOIN beneficiarios ON BnfNumero = FraBnfNumero
				LEFT JOIN ciudades AS cp_cacn ON cp_cacn.CiuNumero = FraCiudadSucursal
				LEFT JOIN ciudades AS cp_cbnf ON cp_cbnf.CiuNumero = FraBnfCiudad
				LEFT JOIN cp_provincias ON cp_provincias.Prov_ID = cp_cbnf.Prov_ID
				LEFT JOIN hd_documentostipos ON tdc_Id = FraBnfDocType
				LEFT JOIN hf_actypes ON hf_actypes.REF = FraTipoCuenta
				LEFT JOIN hd_bancos ON bp_ID = FraBancoID
				LEFT JOIN systemoffice.comr_pub ON cpd_ID = 1
				LEFT JOIN corresponsales AS OutCorresponsal ON OutCorresponsal.CorrNumero = FraCashierCorr
				LEFT JOIN corresponsales AS IncCorresponsal ON IncCorresponsal.CorrNumero = FraIncCorresponsal
				LEFT JOIN hd_monedasiso ON miso_Cod_elite = FraMonDPago
				LEFT JOIN systemoffice.main_users ON main_users.ref ='".$user."'
				LEFT JOIN systemoffice.staff_members ON smb_ID = StaffMember
				LEFT JOIN systemoffice.main_offices ON main_offices.ref = main_users.ref_office
				LEFT JOIN origenes ON origenes.OriNumero = FraOrigen0
				LEFT JOIN origenes AS ori1 ON ori1.OriNumero = FraOrigen1
				LEFT JOIN hd_modospago ON mp_ID = FraModoPago
			WHERE FraID = {$DocObjct}";

		$result=$db->getall($sql);
		$result=$result[0];require_once($_SERVER['DOCUMENT_ROOT'] . "/defaultconf.mex");
                $entidade=Referencia::getEntidade();
                $referencia=$result->referencia;
                $valor=$result->FraEnviado;
                $numeroTlm1 = $result-> CliTelefono;
                $numeroTlm2 = $result-> CliTelefono2 ;
                $numeroTLM = 0;
                $numeroTlm1Check = substr($numeroTlm1,0);
                $numeroTlm2Check = substr($numeroTlm2,0);

              if(($numeroTlm1Check = 9) ){
                    $numeroTLM=$numeroTlm1;
                }
                if(($numeroTlm2Check = 9) ){
                    $numeroTLM=$numeroTlm2;
                }
                //if referencia entidade valor > 0 send sms
               if (strlen($referencia)>2 && strlen($numeroTLM)>0){
                SMS::sendSMS($numeroTLM, $entidade, $referencia, $valor);
                }


        }
	public static function geraRecibo(){
		global $smarty,$db,$GLOBALS,$lang;
		//printArray($_SESSION);
		$user=$_SESSION['TXPTKUS'];
		$smarty->assign('entidade',Referencia::getEntidade());
		$smarty->assign('user',$user);
		$smarty->assign('empresa', Empresa::getNome());
		$smarty->assign('company_adress', 'company_adress');
		$smarty->assign('company_fiscal', 'company_fiscal');
		$smarty->assign('gfx_title','gfx_title');
                $caminho='../_response/bin.php?get=recibo.css';
                //echo $caminho;
		$smarty->assign('css', $caminho);
                $smarty->assign('logo', '../_response/bin.php?get=Logotipos/print_letter_bw.png');
                
		$__arrConcepts = array(0 => 'Remessa de Imigrante', 1 => 'Pagamento de Serviços', 2 => 'Pagamento de Compras');
			
		$DocObjct = $_GET['OB'];
		$sql="SELECT FraID,
			FraOrigen0,
			origenes.OriDireccion,
			origenes.Oriciudad,
			origenes.OriProvincia,
			origenes.OriTelefono,
			FraOrigen1,
			origenes.OriNombre,
			FraReferenciaAg,
			FraFechaIngreso,
			FraFechaAlb,
			FraFecha,
			FraMTCN,
			FraCargoUSD,
			FraEnviadoUSD,
			FraEnviado,
			FraARecibir,
			FraCambio,
			FraTasa,
			FraTasaAgn,
			FraCargo,
			FraMonCobro,
			FraMonDPago,
			FraMonPagoISO,
			FraStatus,
			FraMensaje,
			FraNotas,
			FraConcepto,
			FraCliNumero,
			FraProm,
			FraTaxProm,
			FraModo,
			FraModoPago,
			FraAgenciaPago,
			FraCliNumero AS CliNumero,
			FraCliNombre AS CliNombre,
			FraCliDomicilio AS CliDomicilio,
			FraCliPisoPuerta AS CliPisoPuerta,
			FraCliPortal AS CliPortal,
			FraCliLocation AS CliLocation,
			FraCliNacionalidad AS CliNacionalidad,
			FraCliDNI AS CliDNI,
			FraCliCiudad AS CliCiudad,
			FraCliCP AS CliCP,
			FraCliTelefono AS CliTelefono,
			FraCliTelefono2 AS CliTelefono2,
			FraCliObs AS ClObs,
			FraBnfNombre AS BnfNombre,
			FraBnfNumero AS BnfNumero,
			IF(FraModo=1,BnfNumExt,FraConcepto) AS BnfNumExt,
			FraBnfDireccion AS BnfDireccion,
			FraBnfCedula AS BnfCedula,
			FraBnfCiudad AS BnfCiudad,
			FraBnfTelefono AS BnfTelefono,
			FraBnfPais AS BnfPais,
			FraBnfBarrio AS BnfBarrio,
			FraCtaBenef AS cb_Id,
			FraCuenta AS cb_Cuenta,
			FraBancoID AS BancoID,
			FraCuenta_mod AS cb_Cuenta_mod,
			FraCuenta_prx AS cb_Cuenta_prx,
			FraCuenta_sux AS cb_Cuenta_sux,
			FraSucursal AS cb_Sucursal,
			FraCiudadSucursal AS cb_CiudadSucursal,
			FraTipoCuenta AS cb_Tp,
			bp_Name AS cb_Banco,
			miso_ID,
			mp_ModoPago,
			IF(FraModo=1,OutCorresponsal.CorrNombre,IncCorresponsal.CorrNombre) AS CorrNombre,
			IF(FraModo=1,OutCorresponsal.CorrNumero,IncCorresponsal.CorrNumero) AS CorrNumero,
			IF(FraModo=1,OutCorresponsal.CorrDireccion,IncCorresponsal.CorrDireccion) AS CorrDireccion,
			IF(FraModo=1,OutCorresponsal.CorrAdicionalMailText,IncCorresponsal.CorrAdicionalMailText) AS CorrAdicionalMailText,
			IF(FraModo=1,OutCorresponsal.CorrReceipt,IncCorresponsal.CorrReceipt) AS CorrReceipt,
			cpd_Text,
			ori1.OriTipo AS Ori1Tipo,
			ori1.OriNombre AS Ori1Nombre,
			tdc_Tipo AS BnfDocType,
			hf_actypes.TYPE_NAME AS cb_TipoCuenta,
			hd_bancos.bp_Name AS cb_Banco,
			Prov_Provincia AS BnfProvincia,
			cp_cacn.CiuCiudad AS cb_CiudadSucursal,
			cp_cbnf.CiuCiudad AS BnfCiudad,
			smb_Name AS UserName,
			FraReferenciaMB as referencia
			FROM officeschema.facturas
				INNER JOIN officeschema.facturasextjoins ON FraExtID = FraID
				LEFT JOIN officeschema.facturas_income ON FraIncID = FraID
				LEFT JOIN beneficiarios ON BnfNumero = FraBnfNumero
				LEFT JOIN ciudades AS cp_cacn ON cp_cacn.CiuNumero = FraCiudadSucursal
				LEFT JOIN ciudades AS cp_cbnf ON cp_cbnf.CiuNumero = FraBnfCiudad
				LEFT JOIN cp_provincias ON cp_provincias.Prov_ID = cp_cbnf.Prov_ID
				LEFT JOIN hd_documentostipos ON tdc_Id = FraBnfDocType
				LEFT JOIN hf_actypes ON hf_actypes.REF = FraTipoCuenta
				LEFT JOIN hd_bancos ON bp_ID = FraBancoID
				LEFT JOIN systemoffice.comr_pub ON cpd_ID = 1
				LEFT JOIN corresponsales AS OutCorresponsal ON OutCorresponsal.CorrNumero = FraCashierCorr
				LEFT JOIN corresponsales AS IncCorresponsal ON IncCorresponsal.CorrNumero = FraIncCorresponsal
				LEFT JOIN hd_monedasiso ON miso_Cod_elite = FraMonDPago
				LEFT JOIN systemoffice.main_users ON main_users.ref ='".$user."'
				LEFT JOIN systemoffice.staff_members ON smb_ID = StaffMember
				LEFT JOIN systemoffice.main_offices ON main_offices.ref = main_users.ref_office
				LEFT JOIN origenes ON origenes.OriNumero = FraOrigen0
				LEFT JOIN origenes AS ori1 ON ori1.OriNumero = FraOrigen1
				LEFT JOIN hd_modospago ON mp_ID = FraModoPago
			WHERE FraID = {$DocObjct}";

		$result=$db->getall($sql);
		$result=$result[0];
		//printArray($result);die;
		$sql='select referencia from facturas
			join facturasextjoins on  facturasextjoins.FraExtID= facturas.FraID
			where facturas.FraID='.$result->FraID .';';
		$referencia=$db->getall($sql);
		$referencia=$referencia[0]->referencia;

		$smarty->assign('referencia',$referencia);
		//echo $referencia; die;

		//FraARecibir
		$smarty->assign('valor',$result->FraEnviado);


		if ($result->BnfNumExt > 0) {
			$GETADC = $GLOBALS['MYT']->db_array("
			SELECT FraAdcCota, FraAdcBem, FraAdcGroup, FraAdcIdentifier, BnfExtGroup, BnfExtTransactionType, BnfExtGood, BnfExtCota, BnfExtInvoice
				FROM facturas_adicional
					INNER JOIN beneficiariosinstitucionais ON BnfExtNumero = $result->BnfNumero
					WHERE FraAdcID = $result->FraID");
		}
		if ($result->FraCliNumero > 0) {
			$pontos = $db->getall("SELECT * FROM
				(SELECT bonusinvoice.REF, FraID, DATE(bns_Time) AS bns_Time, CONCAT(FraOrigen0,'-',LPAD(FraReferenciaAg,6,0)) AS FraReferencia, IF(bns_Type=6,`bonusproducts`.NAME,bni_Name) AS bni_Name, bns_Type, FraEnviado, Bns_Amount, bns_Balance, bac_Balance, IF(`bonusproducts`.NAME IS NOT NULL, `bonusproducts`.NAME, bonuscampaigns.NAME) AS NAME
					FROM bonusinvoice
					LEFT JOIN facturas ON FraID = bns_Fra
					LEFT JOIN bonusaccounts ON CLIENT = bac_Client
          			LEFT JOIN bns_invoicetypes ON bns_Type = bni_ID
					LEFT JOIN bonuscampaigns ON bonuscampaigns.REF = bonusinvoice.CAMPAIGN
					LEFT JOIN bonusproducts ON bns_Product = `bonusproducts`.REF
					WHERE CLIENT = {$result->FraCliNumero}
					ORDER BY REF DESC LIMIT 0,5) AS a
					ORDER BY REF ASC");

		}
		$GETOffices = $db->getall("SELECT OriCiudad, OriTelefono FROM origenes WHERE OriTipo = 2 AND OriActivo = 1 AND OriNumero > 800 ORDER BY OriNombre");
		$Serials = $db->getall("SELECT * FROM cur_serials WHERE refOperation = {$result->FraID} AND Status != 5");
		if ($result->FraStatus == 9) {
			$GetHistory = $db->getall("SELECT * FROM hd_historiagiros WHERE edg_Operacion = " . $result->FraID);
		}
		if ($result->FraCambio > 0) {
			$result->FraTasa = $result->FraTasaAgn / $result->FraCambio;
		}
		if ($result->Ori1Tipo == 1) {
			$Qunt = 1;
		} else {
			$Qunt = 2;
		}

		for ($q = 1; $q <= $Qunt; $q++) {
                        //$caminho='../_response/bin.php?get=facebook';
			//$smarty->assign('gfx', $caminho);
                        

                    $smarty->assign('orkut', '../_response/bin.php?get=orkut.jpg');
                    $smarty->assign('facebook', '../_response/bin.php?get=facebook.jpg');
                    
			$smarty->assign('gfx_title', 'titulo');
			$smarty->assign('nomeDaEmpresa', Empresa::getNome());
			$smarty->assign('nifDaEmpresa', Empresa::getNif());
			$smarty->assign('banco', 'Banco de Portugal');
			$smarty->assign('company_adress', Empresa::getMorada());
			$smarty->assign('capitalSocial', Empresa::getCapitalSocial());
			$smarty->assign('webSite', Empresa::getWebSite());
			$smarty->assign('company_fiscal', $lang['company_fiscal']);

			$smarty->assign('OriNombre', $result->OriNombre);
			$smarty->assign('OriDireccion', $result->OriDireccion);
			$smarty->assign('Oriciudad', $result->Oriciudad);
			$smarty->assign('OriProvincia', $result->OriProvincia);
			$smarty->assign('OriTelefono', $result->OriTelefono);

			$smarty->assign('url', $GLOBALS['URL']);
			$smarty->assign('CliNumero', $result->CliNumero);
			$smarty->assign('CliDNI', $result->CliDNI);
			$smarty->assign('CliNombre', $result->CliNombre);
			$smarty->assign('CliDomicilio', $result->CliDomicilio);
			$smarty->assign('CliPortal', $result->CliPortal);
			$smarty->assign('CliPisoPuerta', $result->CliPisoPuerta);
			$smarty->assign('CliCP', $result->CliCP);
			$smarty->assign('CliCiudad', $result->CliCiudad);
			$smarty->assign('CliTelefono', $result->CliTelefono);
			$smarty->assign('CliTelefono2', $result->CliTelefono2);
			$smarty->assign('BnfNombre', $result->BnfNombre);

			$smarty->assign('BnfDireccion', $result->BnfDireccion);
			$smarty->assign('BnfBarrio', $result->BnfBarrio);
			$smarty->assign('BnfCiudad', $result->BnfCiudad);
			$smarty->assign('BnfProvincia', $result->BnfProvincia);


			if ($result->BnfTelefono > 0) {
				$smarty->assign('BnfTelefono', $result->BnfTelefono);
			} else {
				$smarty->assign('BnfTelefono', '0000000000');
			}

			if ($result->BnfNumExt > 0) {
				if (isset($GETADC[1]) && $GETADC[1]['BnfExtTransactionType'] == 1) {
					$smarty->assign('GETADC1', 'GETADC1');
					$smarty->assign('FraAdcBem', $GETADC[1]['FraAdcBem']);
					$smarty->assign('FraAdcGroup', $GETADC[1]['FraAdcGroup']);
					$smarty->assign('FraAdcCota', $GETADC[1]['FraAdcCota']);
				}
				if (isset($GETADC[1]) && $GETADC[1]['BnfExtTransactionType'] == 2) {
					$smarty->assign('GETADC2', 'GETADC2');
					$smarty->assign('FraAdcCota', $GETADC[1]['FraAdcIdentifier']);
				}
			}
			switch ($result->FraModoPago){
				case 1:
					$smarty->assign('FraModoPago1', 'FraModoPago1');
					$smarty->assign('cb_Banco', $result->cb_Banco);
					$smarty->assign('cb_Sucursal', $result->cb_Sucursal);
					$smarty->assign('cb_CiudadSucursal', $result->cb_CiudadSucursal);
					$smarty->assign('BancoID', $result->BancoID);
					$smarty->assign('CorrNumero', $result->CorrNumero);
					$smarty->assign('cb_Cuenta', $result->cb_Cuenta);
					$smarty->assign('cb_Tp', $result->cb_Tp);
					$smarty->assign('cb_Cuenta_prx', $result->cb_Cuenta_prx);
					$smarty->assign('cb_Cuenta_sux', $result->cb_Cuenta_sux);
					$smarty->assign('cb_Cuenta_mod', $result->cb_Cuenta_mod);

					break;
				case 2:
					$smarty->assign('FraModoPago2', 'FraModoPago2');
					$smarty->assign('FraAgenciaPago', $result->FraAgenciaPago);
					$smarty->assign('codigo', $result->FraMTCN);
					break;
			}

			$bpcorrconv=bpcorrconv($result->BancoID, $result->CorrNumero, $result->cb_Cuenta, $result->cb_Tp, $result->cb_Cuenta_prx, $result->cb_Cuenta_sux, $result->cb_Cuenta_mod);
			$smarty->assign('bpcorrconv', $bpcorrconv);

			$smarty->assign('cb_TipoCuenta', $result->cb_TipoCuenta);
			$smarty->assign('CorrReceipt', $result->CorrReceipt);
			if ($result->FraStatus == 9) {
				$smarty->assign('cancelado', 'CANCELADO');
				if (isset($GetHistory[1])) {
					$smarty->assign('motivo', $GetHistory[1]['edg_Motivo']);
				}
			}
			$smarty->assign('FraMensaje', $result->FraMensaje);
			$smarty->assign('FraNotas', $result->FraNotas);
			$smarty->assign('FraOrigen0', $result->FraOrigen0);
			$smarty->assign('Ori1Nombre', $result->Ori1Nombre);
			$smarty->assign('Conceito', $__arrConcepts[$result->BnfNumExt]);


			$smarty->assign('FraFechaIngreso', $result->FraFechaIngreso);
			$smarty->assign('FraOrigen0', $result->FraOrigen0);
			$smarty->assign('FraReferenciaAg', sprintf("%06d", $result->FraReferenciaAg));
			$smarty->assign('FraID', $result->FraID);
			$smarty->assign('FraTasa', number_format($result->FraTasa, 4));
			$smarty->assign('CorrAdicionalMailText', $result->CorrAdicionalMailText);


			/*     * ******************** */

			if ($result->FraModo == 1) {
				$smarty->assign('FraModo', $result->FraModo);
				$smarty->assign('FraMonCobro', $_SESSION['TXPTCURS'][$result->FraMonCobro]['CurLabel']);
				$smarty->assign('FraEnviado', number_format($result->FraEnviado + $result->FraCargo, 2, ',', ''));
				$smarty->assign('FraEnviadoUSD', number_format($result->FraEnviadoUSD + $result->FraCargoUSD, 2, ',', ''));
				$smarty->assign('FraCargo', number_format($result->FraCargo, 2, ',', ''));
				$smarty->assign('FraCargoUSD', number_format($result->FraCargoUSD, 2, ',', ''));
				$smarty->assign('FraProm', number_format($result->FraProm, 2, ',', ''));
				$smarty->assign('FraEnviado', number_format($result->FraEnviado + $result->FraProm, 2, ',', ''));
			}

			$smarty->assign('miso_ID', $result->miso_ID);
			$smarty->assign('FraARecibir', number_format($result->FraARecibir, 2, ',', ''));
			$smarty->assign('FraMonPagoISO', $result->FraMonPagoISO);
			$smarty->assign('mp_ModoPago', $result->mp_ModoPago);


			//printArray($pontos);
			if (isset($pontos)) {
				$smarty->assign('pontos', $pontos);
				$smarty->assign('pontosTotal', 0);
				$smarty->assign('pontosEnviados', 0);
			}

			$smarty->assign('GFX', $GLOBALS['GFX']);
			$smarty->assign('rand', rand(0, 9));

			$smarty->assign('CurLabel', $_SESSION['TXPTCURS'][$result->FraMonCobro]['CurLabel']);
			$smarty->assign('FraEnviado', number_format($result->FraEnviado + $result->FraCargo, 2, ',', ''));
			$smarty->assign('FraEnviadoUSD', number_format($result->FraEnviadoUSD + $result->FraCargoUSD, 2, ',', ''));
			$smarty->assign('url', $GLOBALS['URL']);


			//  Sorteios

			if ($result->FraModo == 1) {
				$data = $result->FraFechaIngreso;
				$data0 = "2010-05-10 07:00:00";
				$data1 = "2010-06-30 21:00:00";
				$data2 = "2010-08-31 21:00:00";
				$data3 = "2010-10-31 21:00:00";
				$data4 = "2010-12-31 21:00:00";
				$data5 = "2011-01-31 21:00:00";
				$data6 = "2011-02-28 21:00:00";
				$data7 = "2011-03-31 21:00:00";
				$data8 = "2011-04-30 21:00:00";
                                $data9 = "2011-05-31 21:00:00";
                                $data9 = "2011-06-30 21:00:00";
                                $data9 = "2011-07-31 21:00:00";
				if ($data > $data0) {
					$smarty->assign('data', 'data');
					if (($data < $data1) and ($data > $data0)) {
						$Sort_Number = 1;
						$Sort_Date = '2010-07-01 15h00';
					} elseif (($data < $data2) and ($data > $data1)) {
						$Sort_Number = 2;
						$Sort_Date = '2010-09-01 15h00';
					} elseif (($data < $data3) and ($data > $data2)) {
						$Sort_Number = 3;
						$Sort_Date = '2010-11-02 15h00';
					} elseif (($data < $data4) and ($data > $data3)) {
						$Sort_Number = 4;
						$Sort_Date = '2011-01-03 15h00';
					} elseif (($data < $data5) and ($data > $data4)) {
						$Sort_Number = 5;
						$Sort_Date = '2011-02-01 15h00';
					} elseif (($data < $data6) and ($data > $data5)) {
						$Sort_Number = 6;
						$Sort_Date = '2011-03-01 15h00';
					} elseif (($data < $data7) and ($data > $data6)) {
						$Sort_Number = 7;
						$Sort_Date = '2011-04-01 15h00';
					} elseif (($data < $data8) and ($data > $data7)) {
						$Sort_Number = 8;
						$Sort_Date = '2011-05-01 15h00';
					}
					if ($Sort_Number > 4) {
						$print_SortNumber = $Sort_Number - 4;
					} else {
						$print_SortNumber = $Sort_Number;
					}
					$GetNumeros = $db->getall("SELECT numeros FROM promotions_sorteios WHERE {$result->FraID} IN (sorteio" . $Sort_Number . "_nremessa) AND numeros < 200000");
					if (isset($GetNumeros[1])) {
						$smarty->assign('GetNumeros', 'GetNumeros');
						$smarty->assign('dataDeFechoDeIngresso', substr($result->FraFechaIngreso, 0, 4));
						$smarty->assign('Sort_Date', $Sort_Date);
						$smarty->assign('Sort_Number', $Sort_Number);
						$numeros = "";
						//printArray($GetNumeros);
						$tamanho =count($GetNumeros);
						for ($f = 0; $f < $tamanho; $f++) {
							$numeros .=$GetNumeros[$f]->numeros.', ';
						}
						//retira ultima virgula
						$numeros=substr($numeros, 0, -2);
						//var_dump($numeros);
						$numeros='<b>'.$numeros.'</b>';
						$smarty->assign('numeros', $numeros);
					}
				}

		}
		$smarty->display('index.tpl');
	}
}
}